<!Doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<title></title>
	<style>
		
	</style>
</head>
<body>
	<input id="start" type="button" value="开始" >
	<input id="pause" type="button" value="暂停" >
	<script>
		function $(id){return document.getElementById(id)}
		var start = $('start');
		var pause = $('pause');
		var foo = count();
		start.onclick = foo.startCount;
		pause.onclick = foo.pauseCount;
		function count(){
			var timer;
			var i = 0;
			var o = {
				startCount: function(){
					clearInterval(timer);
					function doCount(){
						i++;
						console.log(i);
					}
					timer = setInterval(doCount,500);
				},
				pauseCount: function(){
					clearInterval(timer);
				}
			}
			return o;
		}
	</script>
</body>
</html>